-
Notifications
You must be signed in to change notification settings - Fork 196
Add ProptestResultExt
with prop_assume_ok
helper
#589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
8d76042
to
aab15d4
Compare
proptest/src/test_runner/errors.rs
Outdated
|
||
/// Extension trait for `Result<T, E>` to provide additional functionality | ||
/// specifically for prop test cases. | ||
pub trait ResultExt<T, E> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a nice ergonomic addition, but ResultExt
is pretty common. can we name this ProptestResultExt
instead?
also seems like a good case for a sealed trait
e.g. from blog post
mod private {
pub trait Sealed {}
}
pub trait SealedTrait : private::Sealed {
fn method(&self);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added.
proptest/src/test_runner/errors.rs
Outdated
|
||
impl<T, E> ResultExt<T, E> for Result<T, E> { | ||
#[track_caller] | ||
fn assume_ok(self) -> Result<T, TestCaseError> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you think about naming prop_assume_ok
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me. Changed.
ResultExt
with assume_ok
helperProptestResultExt
with assume_ok
helper
ProptestResultExt
with assume_ok
helperProptestResultExt
with prop_assume_ok
helper
I found myself using
prop_assume!(result.is_ok())
a lot before unwrapping someResult
value that I use while testing. So to make life easier I come to the following api addition.This allows to write test like the following.